<template>
  <div class="toast" v-show="isShow">
    <div class="toast-text">{{ message }}</div>
  </div>
</template>

<script>
export default {
  name: "Toast",
  props: {
    /* message: {
      type: String,
      default: "",
    },
    isShow: {
      type: Boolean,
      default: false,
    }, */
  },
  data() {
    return {
      message: "",
      isShow: false,
    };
  },
  methods: {
    // 给参数默认时间1500 es6写法
    show(message = "默认文字", duration = 1500) {
      // duration = duration || 1500 // 以前写法
      this.isShow = true;
      this.message = message;

      setTimeout(() => {
        this.isShow = false;
        this.message = "";
      }, duration);
    },
  },
};
</script>

<style scoped>
.toast {
  z-index: 2;
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(0, 0, 0, 0.6);
}
.toast-text {
  z-index: 3;
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(20, 20, 20, 0.8);
  color: #fff;
  font-size: 16px;
  padding: 10px 15px;
  border-radius: 8px;
}
</style>